package cn.cmdr.service.ServiceImpl;

import cn.cmdr.mapper.RoleMapper;
import cn.cmdr.pojo.Role;
import cn.cmdr.service.RoleService;
import cn.cmdr.vo.PageVo;
import cn.cmdr.vo.RoleVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleMapper,Role> implements RoleService {

    @Resource
    private RoleMapper roleMapper;
    @Override
    public List<Role> getRoleList() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("whether",1);
        return roleMapper.selectList(queryWrapper);
    }

    @Override
    public PageVo getPageRoleList(Integer pageNo, Integer pageSize, RoleVo roleVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(roleVo.getRoleName()),"role_name",roleVo.getRoleName());
        IPage<Role> iPage = super.page(page,queryWrapper);
        return new PageVo(iPage.getRecords(),iPage.getTotal());
    }

    @Override
    public void add(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public void update(Role role) {
        roleMapper.updateById(role);
    }

    @Override
    public void deleteById(Integer id) {
        roleMapper.deleteById(id);
    }

    @Override
    public Role getrole(Integer rid) {
        return roleMapper.selectById(rid);
    }
}
